Potential fix for code scanning alert no. 1: Code injection#5
Merged
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/SyntheticAutonomicMind/SAM/security/code-scanning/1
General fix: avoid interpolating
${{ ... }}expressions directly in shell command bodies when they may contain untrusted data. Instead, assign them to environment variables usingenv:at the step level, and then reference them using the shell’s own variable expansion syntax ($VAR). This prevents expression-time concatenation with shell syntax and reduces the risk of command injection.Best concrete fix here:
In the "Extract version from workflow run" step:
env:block that exposesgithub.event_name,github.event.inputs.version, andgithub.event.workflow_run.head_branchas environment variables (e.g.,EVENT_NAME,INPUT_VERSION,HEAD_BRANCH).$EVENT_NAME,$INPUT_VERSION, and$HEAD_BRANCHinstead of${{ ... }}directly inrun:. This addresses the flagged injection on line 37 (head_branch) and also hardens the other uses in that step.In the "Update SAM cask" step:
env:block mappingsteps.version.outputs.version,steps.hash.outputs.sha256, andsteps.asset.outputs.urlto environment variables (VERSION,SHA256,DMG_URL).VERSION="...",SHA256="...", andDMG_URL="..."assignments from the script body, and just use$VERSION,$SHA256,$DMG_URLwhere needed (the current snippet only usesVERSIONandSHA256inechoandsed; leaveDMG_URLset inenvfor possible future use).In the "Commit and push" step:
env:block mappingsteps.version.outputs.versiontoVERSION.VERSION="${{ steps.version.outputs.version }}"and continue using$VERSIONin the commit message.No new methods or imports are required; only YAML changes within
.github/workflows/update-homebrew-cask.ymlin the shown steps.Suggested fixes powered by Copilot Autofix. Review carefully before merging.